﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Permission.MVCFilter;
using Microhard.Permission_MembershipImpl;
using Microhard.Permission.Interfaces;
using Microhard.Core;
using Microhard.Permission.Models;


namespace Microhard.FMCG.WebUI.Areas.Tools.Controllers
{
    public class PCDController : Controller
    {
        private PCDCache cache = new PCDCache();

        [MVCFilterAtrForLogon()]
        public ActionResult GetProvince()
        {
            var data = cache.GetChild(Core.DBUtility.PCD.Province, null);
            var sl = from d in data
                     select new SelectListItem
                     {
                         Text = d.Name,
                         Value = d.Value
                     };
            return Json(sl, JsonRequestBehavior.AllowGet);
        }

        [MVCFilterAtrForLogon()]
        public ActionResult GetCity(int provinceID)
        {
            var data = cache.GetChild(Core.DBUtility.PCD.City, provinceID.ToString());
            var sl = from d in data
                     select new SelectListItem
                     {
                         Text = d.Name,
                         Value = d.Value
                     };
            return Json(sl, JsonRequestBehavior.AllowGet);
        }

        [MVCFilterAtrForLogon()]
        public ActionResult GetDistinct(int cityID)
        {
            var data = cache.GetChild(Core.DBUtility.PCD.Distince, cityID.ToString());
            var sl = from d in data
                     select new SelectListItem
                     {
                         Text = d.Name,
                         Value = d.Value
                     };
            return Json(sl, JsonRequestBehavior.AllowGet);
        }

    }
}
